<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>BeginCode后台管理系统-用户管理</title>
    <link rel="stylesheet" href="${rc.contextPath}/layui/css/layui.css" media="all">
    <script src="${rc.contextPath}/layui/layui.all.js"></script>
    <script src="${rc.contextPath}/js/jquery.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
<#include "common/top.ftl">
<#include "common/left.ftl">
    <div class="layui-body">

        <div class="layui-form" style="padding-top: 30px">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">Email</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" id="email" lay-verify="title" placeholder="email"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="flag" id="flag" lay-filter="flag">
                            <option value="CREATE" selected="">未审核</option>
                            <option value="EFFECT">通过</option>
                            <option value="UNEFFECT">未通过</option>
                            <option value="FROZEN">冻结</option>
                            <option value="DELETE">删除</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" id="query" lay-filter="userQuery">查询</button>
                    </div>
                </div>
            </div>
        </div>

        <table id="userList" lay-filter="opt"></table>
    </div>
<#include "common/foot.ftl">
</div>
</body>
</html>


<script type="text/html" id="optTools">
    <a class="layui-btn layui-btn-xs" lay-event="pass">通过</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="failed">不通过</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="frozen">冻结</a>
</script>

<script type="text/html" id="usernameTpl">
    <a href="" class="layui-table-link">{{d.username || ''}}</a>
</script>


<script src="${rc.contextPath}/layui/layui.all.js" charset="utf-8"></script>
<script>
    layui.use(['table', 'form'], function () {
        var table = layui.table;
        var jquery = layui.$;
        //渲染
        table.render({
            id: 'userReload'
            , elem: '#userList'
            , height: 'full-200'
            , url: '${rc.contextPath}/admin/user/queryWaitCheckUser'
            , cellMinWidth: 80
            , page: true
            , request: {
                pageName: 'pageNo' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , where: {
                flag: jquery("#flag").val(),
                email: jquery("#email").val()
            }
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'userId', title: 'ID', fixed: 'left', unresize: true}
                , {field: 'email', title: '邮箱'}
                , {field: 'nickName', title: '昵称'}
                , {field: "cdate", title: '注册时间'}
                , {field: 'flag', title: '状态'}
                , {fixed: 'right', title: '操作', toolbar: '#optTools'}
            ]]

        });

        //监听工具条
        table.on('tool(opt)', function (obj) {
            var data = obj.data;
            var url;
            if (obj.event === 'pass') {
                url = "${rc.contextPath}/admin/user/checkPass";
            } else if (obj.event === 'failed') {
                url = "${rc.contextPath}/admin/user/checkFailed";
            } else if (obj.event === 'frozen') {
                url = "${rc.contextPath}/admin/user/frozen";
            } else {
                layer.msg('非法操作', {
                    icon: 2,
                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                });
                layer.close(index);
            }
            jquery.post(
                    url
                    , {"userId": data.userId}
                    , function (result) {
                        if (result.success && result.data) {
                            layer.msg('操作成功', {
                                icon: 1,
                                time: 1000 //2秒关闭（如果不配置，默认是3秒）
                            });
                        }
                        if (result.success) {
                            reloadTable();
                            layer.close(index);
                        }
                    }
            );
        });

        jquery('#query').on('click', function () {
            reloadTable();
        });

        function reloadTable() {
            table.reload('userReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , request: {
                    pageName: 'pageNo' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                , where: {
                    flag: jquery("#flag").val(),
                    email: jquery("#email").val()
                }
            });
        }

    });
</script>